package com.wangzhenyu.learn.test.android_.storage_

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract

//用来使用SAF的activityResult
class SAFActivityResult : ActivityResultContract<String, Uri?>() {
    override fun createIntent(context: Context, input: String): Intent {
        return Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
            addCategory(Intent.CATEGORY_OPENABLE)
            type = "image/*"
        }
    }

    override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
        val data = intent?.data
        return if (resultCode == Activity.RESULT_OK && data != null) data else null
    }
}